package libra;

import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 基于Nacos提供的注解，实现注解式自动的应用方式
 */
@RestController
public class TestController {
	// 测试普通请求
	@RequestMapping("test")
	public Object test() {
		return Map.of("code",0);
	}
	
	// 测试REST请求
	@RequestMapping("rest/{val}")
	public Object testRest( @PathVariable("val") String str ) {
		return Map.of("code",0, "val", str);
	}
	
	// 测试@SentinelResource注解应用
	int i = 1;
	@Autowired
	private TestService service;
	@RequestMapping("testSentinelResource")
	public Object testSentinelResource( HttpServletResponse resp ) throws Throwable {
		// 传入resp，交由底层修改状态码。否则默认对外都会是正常返回200状态码
		return Map.of("msg", service.normalExec("testSentinelResource", i++, resp));
	}
}
